<template>
  <view>
    <view class="cu-bar bg-white search fixed"
          :style="[{top:CustomBar + 'px'}]">
      <view class="search-form round">
        <text class="cuIcon-search"></text>
        <input type="text" v-model="searchTxt" placeholder="输入产品名称"
               confirm-type="search"/>
      </view>
      <view class="action">
        <button class="cu-btn round text-custom-bg text-white"
                @tap.stop="searchOrderList">搜索</button>
      </view>
    </view>
    <view class="margin-sm" style="margin-top: 100rpx">
      <view class="cu-list menu-avatar">
        <block v-for="(item,index) in msgList" :key="index">
          <order-one-list :order="item"></order-one-list>
        </block>
      </view>
      <view class="text-center padding text-gray">~~~~我是有底线的~~~~</view>
    </view>

    <!-- 资讯按钮 -->
    <view v-if="orderKey ==1" class="cu-bar bg-white tabbar shop shadow edit-fixed">
<!--      <button class="action text-gray text-shadow">-->
<!--        <view class='cuIcon-community text-gray'>-->
<!--        </view>-->
<!--      </button>-->
      <view class="action text-gray text-shadow">
        <text class="text-sm">总共{{msgList.length}} 单</text>
      </view>
      <view class="submit margin-left-xl text-xl text-custom-bg text-white" @tap.stop="submitVerifyOrder">
          <text class="text-white">核销</text>
      </view>
    </view>

  </view>
</template>

<script setup lang="ts">
import {onReachBottom, onLoad} from "@dcloudio/uni-app";
import {useStore} from "@/common/store";
import {computed, onMounted, ref} from "vue";
import {findOwnerOrderStasticList, verifyOrder} from "@/common/api/order";
import OrderOneList from "../../components/OrderOneList.vue";

const store = useStore();

const token = computed(() => store.token)
const userId = computed(() => store.userId)
const CustomBar = ref(0)
const msgList = ref([])
const searchTxt = ref('')

const orderKey = ref('')

const initMsgList = (value: string) => {
  findOwnerOrderStasticList({
     adminId : userId.value ||0,
     orderType : orderKey.value,
     search: value
  }).then(res => {
    msgList.value = res.data;
  })
}

const searchOrderList = () => {
  initMsgList(searchTxt.value);
}

const submitVerifyOrder = () => {
  if (msgList.value && msgList.value.length ==0) {
    uni.showToast({
      title: '没有发现订单不需要核销!',
      duration: 2000,
      icon: 'none'
    });
    return false;
  }

  uni.showModal({
    title: '提示',
    content: '确定核销？',
    success: function (res) {
      if (res.confirm) {
        verifyOrder({
          adminId: userId.value ||0,
          orders: msgList.value
        }).then(res => {
          let hxId = res.data;
          uni.showToast({
            title: '核销成功!',
            duration: 2000,
            icon: 'none',
            success: function (res) {
              uni.navigateTo({
                url: `/pages/order/VerifyOrderResult?id=${hxId}`
              })
            }
          });
        })
      }
    }
  });

}

const redirectDetail = (item: any) => {
  uni.navigateTo({
    url: `/pages/message/messageInfo?id=${item.id}`
  })
}

onLoad((options) =>{
  orderKey.value = options.orderKey;
})

onMounted(async () => {
  initMsgList('');
})
</script>

<style>
.indexes {
  height: 70vh;
  margin-top: 50px;
}
.edit-fixed {
  position: fixed;
  width: 100%;
  bottom: 0;
  z-index: 1024;
  box-shadow: 0 1rpx 6rpx rgba(0, 0, 0, 0.1);
}

</style>
